#include "showclock.h"
#include <QTimer>
#include <QTime>
#include <QPalette>
ShowClock::ShowClock(QWidget *parent) :
    QLCDNumber(parent)
{
  //  setSegmentStyle(Filled);
    setNumDigits (8);

    setFrameShape(QFrame::NoFrame);		//NoFrame
    setSegmentStyle(QLCDNumber::Flat);	//FillBlack

    QPalette palette = this->palette();
    palette.setBrush(QPalette::WindowText, QBrush(QColor(255, 0, 0, 255)));			//时钟文字颜
    setPalette(palette);

    QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(showTime()));
    timer->start(1000);

    showTime();

    setWindowTitle(tr("Digital Clock"));
    resize(185, 92);
    setNumDigits(15);
    setSegmentStyle(QLCDNumber::Flat);
}

void ShowClock::showTime()
{
    QTime time = QTime::currentTime();
    QString timeString = time.toString("hh:mm:ss").left(8);
    QDate date = QDate::currentDate();
    QString dateString;
    dateString.sprintf(" %2d-%2d", date.month(),date.day());
    QString text = timeString + dateString;
    if((time.second() % 2) == 0)
    {
        text[5] =' ';
    }
    if(date.month() < 10)
    {
        text[9] ='0';
    }
    if(date.day() < 10)
    {
        text[12] ='0';
    }
    display(text);
}
